package com.wwwc.admin.web.servlet;

import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.math.BigDecimal;
import java.io.*;

import com.wwwc.util.web.*;

public class Dispatcher extends HttpServlet {

    public void doPost(HttpServletRequest request, HttpServletResponse response) {	
	response.setContentType("text/html");
	HttpSession session = request.getSession();
	String user_ip      = request.getRemoteAddr();

	String selectedScreen = request.getServletPath();
	request.setAttribute("selectedScreen", selectedScreen);
	PrintWriter out = null;

	try {
	    out = response.getWriter();
	} catch(IOException e) {
	    System.out.println("Dispatcher:100");
	}
 
	if (selectedScreen.equals("/logon")) {
	    System.out.println(DebugBean.getInputs("Dispatcher:logon",request));
	    try {
		request.getRequestDispatcher("/logon.jsp").forward(request, response);
	    } catch(Exception e) {
		System.out.println("Dispatcher:101");
	    }	
	} 

	if (selectedScreen.equals("/logout")) {
	    session.invalidate();
	    out.println(MyMessage.htmlMessage(MyHtml.makeLinkButton("Log On Again", "'"+request.getContextPath()+"/'").toString()));
	}    

	if (selectedScreen.equals("/logonError")) {
	    request.setAttribute("error","Please check your Username and Password.");
	    try {
		request.getRequestDispatcher("/logon.jsp").forward(request, response);
	    } catch(Exception e) {
		System.out.println("Dispatcher:101");
	    }
	} 

	if (selectedScreen.equals("/index.jsp")) {
	    try {
		request.getRequestDispatcher("/index").forward(request, response);
	    } catch(Exception e) {
		System.out.println("Dispatcher:101");
	    }	
	} 
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response) {   
	doPost(request, response);
    }
}
